package com.example.ks.servlet;

import com.example.ks.dao.impl.UserDaoImpl;
import com.example.ks.entity.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/user-index")
public class UserIndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDaoImpl userDao = new UserDaoImpl();
        try {
            List<User> admins = userDao.getAdminList();
            request.setAttribute("admins", admins);
            request.getRequestDispatcher("user-index.jsp").forward(request, response);
        } catch (SQLException e) {
            e.printStackTrace();
            request.setAttribute("error", "获取管理员列表失败：" + e.getMessage());
            request.getRequestDispatcher("user-index.jsp").forward(request, response);
        }
    }
} 